var app = sm("do_App");
var page = sm("do_Page");
var nf = sm("do_Notification");
var hashdata = mm("do_HashData");
var circleUrl = require("url/circle");
var http = require("helper/http");
var imHelper = require("helper/im");
// 加载头部---begin
var headerAout = ui("headerAout");
var addheader = headerAout.add("header", "source://view/reuse/header.ui", 0, 0);
// andriod返回键
page.on("back", function() {
	app.closePage();
});
// 左上角-返回
var headerLeft = ui(addheader + ".headerLeft");
headerLeft.on("touch", function() {
	app.closePage()
});
//右上角-发布（提交）
var headerRight = ui(addheader+".headerRight");
var headerRight_lableNext = ui(addheader+".labelNext");
headerRight_lableNext.text = "完成";
headerRight_lableNext.visible = true;
headerRight.on("touch", function() {
	submitModifyRemark();
});
//头部-中间-标题
var header = ui("header");
header.bindData(hashdata);
hashdata.addData({
	"labelTitle" : "修改名称",
})
header.refreshData();
//加载头部---end

var circleId = null;

//页面装载完成后，开始初始化工作
page.on("loaded", function(){
	circleId = page.getData().circleId;
	ui("textRemark").text = page.getData().circleName;
});

ui("do_ALayout_del").on("touch",function(){
	ui("textRemark").text  = "";
});

function submitModifyRemark(){
	var chatName = ui("textRemark").text;
	if(chatName == "" || chatName.length ==0){
		nf.toast("请输入名称");
		return;
	}
	if(chatName.length > 30){
		nf.toast("最多只能输入30个字.");
		return;
	}
	if(circleId!=null){
		http.post(circleUrl.url.base.updateName,{"id":circleId,"name":chatName},function(data){
			imHelper.reflashCacheGroup(circleId);
			app.closePage({chat_name_update:true,"new_name": chatName})
		});
	}
}
